package com.xique.door.project.miniprogram.controller;

import com.xique.common.core.web.controller.BaseController;
import com.xique.common.core.web.domain.AjaxResult;
import com.xique.door.bean.domain.Area;
import com.xique.door.project.miniprogram.bean.request.MiniAreaCodeListRequest;
import com.xique.door.project.miniprogram.bean.vo.MIniAreaVO;
import com.xique.door.service.IAreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("mini/area")
public class MiniAreaController extends BaseController {

  @Autowired private IAreaService tAreaService;

  /** 查询地区码列表 */
  @GetMapping("/list")
  @ResponseBody
  public AjaxResult list(Area tArea) {
    startPage();
    tArea.setLevel(1);
    List<Area> list = tAreaService.selectAreaList(tArea);
    List<MIniAreaVO> volist = new ArrayList<>();
        list.stream()
            .forEach(
                item -> {
                  MIniAreaVO vo = new MIniAreaVO();
                  vo.setAreaCode(item.getAreaCode());
                  vo.setAreaName(item.getAreaName());
                  volist.add(vo);
                });
     return AjaxResult.success(volist);
  }

  /** 查询地区码列表 */
  @GetMapping("/codeList")
  public AjaxResult codeList(@Valid MiniAreaCodeListRequest request) {
    return tAreaService.getAreaCodeList(request);
  }

  /**根据定位获取当前用户最近的小区*/
  @GetMapping("/selectParkInfo")
  public AjaxResult selectParkInfo(String longitude, String latitude){
      return tAreaService.selectParkInfoList(longitude,latitude);
  }
}
